//implement QtThreadImpl
//andycai_sc 2011-05-29

#include "GParallel/GQt/QtThreadImpl.h"

QtThreadImpl::QtThreadImpl(GThread *thread) : GThreadImpl(thread)
{
    m_runableThread = new RunableThread(this);
}

QtThreadImpl::~QtThreadImpl()
{
    delete m_runableThread;
}

void QtThreadImpl::startImpl()
{
    m_runableThread->start();
}

void QtThreadImpl::stopImpl()
{
    m_runableThread->terminate();
}


void QtThreadImpl::joinImpl()
{
    m_runableThread->wait();
}

void QtThreadImpl::sleepImpl(long mseconds)
{
    RunableThread::millsleep(mseconds);
}

QtThreadImpl::RunableThread::RunableThread(GThreadImpl *threadImpl, QObject *parent) :
QThread(parent), m_threadImpl(threadImpl)
{
}

void QtThreadImpl::RunableThread::millsleep(long mseconds)
{
    QThread::msleep(mseconds);
}

void QtThreadImpl::RunableThread::run()
{
    m_threadImpl->exec();
}

GThreadImpl* createThreadFromQt(GThread *_thread)
{
    return new QtThreadImpl(_thread);
}


